import java.util.Arrays;
import java.util.HashMap;

class Solution {
    public static String minWindow(String s, String t) {
        int[] hash1 = new int[128];
        int[] hash2 = new int[128];
        char[] ch1 = s.toCharArray();
        char[] ch2 = t.toCharArray();
        int kinds = 0;
        for(char ch : ch2) {
            if(hash2[ch]++ == 0) {
                kinds++;
            }
        }
        int min = -1,len = 0;
        for(int left = 0,right = 0,count = 0; right < s.length(); right++) {
            char in = ch1[right];
            hash1[in]++;
            if(hash1[in] == hash2[in]) count++;
            while(kinds == count) {
                if(len == 0 || right - left + 1 < len) {
                    len = right - left + 1;
                    min = left;
                }
                char out = ch1[left++];
                if(hash1[out]-- == hash2[out]) count--;
            }
        }
        if(min == -1) return new String();
        else return s.substring(min,len+min);
    }

    public static void main(String[] args) {
        String  s = "ADOBECODEBANC";
        String t = "ABC";
        String ret = minWindow(s,t);
        System.out.println(ret);
       /* HashMap<Character,Integer> hash1 = new HashMap<>();
        hash1.put('c',3);
        hash1.put('d',0);
        System.out.println(hash1.containsKey('c'));
        System.out.println(hash1.containsKey('d'));
        System.out.println(hash1.containsKey('f'));
        */
        /*int[] array = new int[128];
        array['a']++;
        System.out.println(Arrays.toString(array));*/
        //String ss = s.substring(0,0+1);

    }
}